//链式队列
#define MAXSIZE 100//最大队列长度

typedef int QElemType;

typedef struct Qnode{
    QElemType data;
    struct Qnode *next;
}QNode,*QueuePtr;//链表 (QueuePtr--Queue Pointer)

typedef struct{
    QueuePtr front;//队头链表结构体指针
    QueuePtr rear;//队尾链表结构体指针
}LinkQueue;//队列

LinkQueue Q;

//初始化
Status InitQueue(LinkQueue &Q){
    Q.front = Q.rear = (QueuePtr)malloc(sizeof(QNode));
    if(!Q.front) exit(OVERFLOW);
    Q.front->next = NULL;
    return OK;
}

// 入队
Status EnQueue(LinkQueue &Q,QElemType e){
    p = (QueuePtr)malloc(sizeof(QNode));
    if (!p) exit(OVERFLOW);
    p->data=e;
    p->next = NULL;
    Q.rear->next = p;
    Q.rear = p;
    return OK;
}

// 出队
Status DeQueue(LinkQueue &Q,QElemType &e){
    if(Q.front == Q.rear) return ERROR;
    p = Q.front -> next;// 有头节点所以next
    e = p->data;
    Q.front->next = p->next;
    if(Q.rear==p) Q.rear = Q.front;//特殊：删除尾节点
    free(p);
    return OK;
}

// 销毁
Status DestroyQueue(LinkQueue &Q){
    QueuePtr p;
    while(Q.front){
        p=Q.front->next；
        free(Q.front);
        Q.front = p;
    }
    return OK;
}